﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAL;
using EntitiesContainer;
using webstore.Interfaces;

namespace webstore
{
    public partial class MainForm : Form, IViewMain
    {
        public event Action CategorySelected;
        public event Action RowSelected;

        public MainForm()
        {
            InitializeComponent();
            comboProductCategory.SelectedIndexChanged += (sender, args) => Invoke(CategorySelected);
            dataGridProducts.DoubleClick += (sender, args) => Invoke(RowSelected);
        }
        private void Invoke(Action action)
        {
            if (action != null) action();
        }
        public void SetComboBoxCategory(ICollection<string> ProductCategoriesList)
        {
            comboProductCategory.DataSource = ProductCategoriesList;
        }
        public string GetComboBoxCategory()
        {
            return (string)comboProductCategory.SelectedItem;
        }
        public void SetProductPicture(Image img)
        {
            picBoxProduct.Image = img;
        }
        public void SetProduct(string product)
        {
            textBox1.Text = product;
        }
        public void SetDescription(string descriprion)
        {
            textBox3.Text = descriprion;
        }
        public void SetPrice(string price)
        {
            textBox2.Text = price;
        }
        public void SetCategory(string category)
        {
            textBox4.Text = category;
        }
        public int GetId()
        {
            return (int)dataGridProducts.CurrentRow.Cells[0].Value;
        }
        public string GetName()
        {
            return (string)dataGridProducts.CurrentRow.Cells[1].Value;
        }
        public void SetDataGrid()
        {
            dataGridProducts.Rows[0].Cells[1].Value = "123";
        }
        public new void Show()
        {
            Application.Run(this);
        }

   }
}
